<template>
  <BaseBreadcrumb />
  <!--表格-->
  <BaseTable
    ref="baseTable"
    :columns="columns"
    :has-selected="false"
    :api="NOTICE_API_PRE_SUFFER"
    :params="search"
    :is-custom-update="true"
    :extra-button="extraButton"
    @operationChange="drawer.handlerOperation"
  />
  <BaseDrawer v-model:visible="props.visible" v-bind="props">
    <Update v-bind="props" @refresh="drawer.refresh" @close="drawer.close" />
  </BaseDrawer>
</template>

<script lang="ts" setup>
import { defineAsyncComponent, onMounted, ref } from 'vue'
import { columns } from './columns'
import { search } from './search'

import { useDrawer } from '@/hooks/base/DrawerHooks'
import { deptSelected } from '@/api/system/dept'
import { injectCustomUpdateOptions } from '@/utils/form-item-util'
import { NOTICE_API_PRE_SUFFER } from '@/api/system/notice'
import { CustomAction } from '@/components/base/table/BaseTable.vue'
import { Notice } from '@/entity/system/notice'
const Update = defineAsyncComponent(() => import('./Update.vue'))
const drawer = useDrawer(NOTICE_API_PRE_SUFFER, '通知信息')
const props = drawer.props
import api from '@/api/system/notice'
import { useTable } from '@/hooks/base/TableHooks'
const table = useTable()
// 扩展按钮
const extraButton = ref<Array<CustomAction<Notice>>>([
  {
    name: '发布',
    auth: 'publish',
    show: (val) => {
      return val.status == 1 || val.status == 3
    },
    action: async (val) => {
      await api.publish(val.id)
      table.refresh()
    },
  },
  {
    name: '禁用',
    auth: 'disbled',
    show: (val) => {
      return val.status == 2
    },
    action: async (val) => {
      await api.disabled(val.id)
      table.refresh()
    },
  },
])
</script>

<style scoped lang="scss"></style>
